#include "cond.h"

Condition::Condition() {

    num_iteration     = 0;
    num_error 	      = 0;
    num_file 	      = 0;
    num_schrodinger   = 0;
    num_poisson       = 0;
    num_current       = 0;
    num_continuity    = 0;

    type              = 0;
    debug             = 0;
    traps             = 0;

    barrier_left_contact = 0;
    barrier_right_contact = 0;

    precision           = 0;
    initial_bias        = 0;
    final_bias          = 0;
    step_bias           = 0;

    Pz_percentage       = 0;
    Psp_percentage      = 0;
    relax_length        = 0;

    Max_quantum_width   = 0;
    Secure_length       = 0;
    Number_of_eigenvalues = 0;

    fluctuation = 0;
    fluctuation_percentage = 0;

}

/* ---------------------------------------- */
/* ---------------------------------------- */

Condition::Condition(char * filename) {

    FILE * fp; 
	fopen_s(&fp,filename,"r");
    if(!fp) {
      printf("CONDITION Opening file %s, failure!\n",filename);
      exit(1);
    }
    skip_line(fp);
    fscanf_s(fp,"%d",&type);
    fscanf_s(fp,"%d",&debug);
    
    if(type!=1) nrerror("DANGER: the flag type in the input file simulation.inp should be set to 1\n");
    if(debug) {
	printf("DEBUG MODE (Set it off in the file simulation.inp\n)");
	printf("DEBUG MODE (Set it off in the file simulation.inp\n)");
	printf("DEBUG MODE (Set it off in the file simulation.inp\n)");
	printf("DEBUG MODE (Set it off in the file simulation.inp\n)");
    }

    skip_line(fp);
    skip_line(fp);
    fscanf_s(fp,"%s",input_file_name);
    skip_line(fp);
    skip_line(fp);
    fscanf_s(fp,"%d",&num_iteration);
    fscanf_s(fp,"%le",&precision);
    skip_line(fp);
    skip_line(fp);
    fscanf_s(fp,"%d",&num_error);
    fscanf_s(fp,"%d",&num_file);
    fscanf_s(fp,"%d",&num_poisson);
    fscanf_s(fp,"%d",&num_schrodinger);
    fscanf_s(fp,"%d",&num_continuity);
    fscanf_s(fp,"%d",&num_current);
    skip_line(fp);
    skip_line(fp);
    fscanf_s(fp,"%lf",&initial_bias);
    fscanf_s(fp,"%lf",&final_bias);
    fscanf_s(fp,"%lf",&step_bias);
    skip_line(fp);
    skip_line(fp);
    fscanf_s(fp,"%lf",&Pz_percentage);
    fscanf_s(fp,"%lf",&Psp_percentage);
    fscanf_s(fp,"%lf",&relax_length);
    skip_line(fp);
    skip_line(fp);
    fscanf_s(fp,"%d",&traps);
    skip_line(fp);
    skip_line(fp);
    fscanf_s(fp,"%lf",&barrier_left_contact);
    fscanf_s(fp,"%lf",&barrier_right_contact);
    skip_line(fp);
    skip_line(fp);
    fscanf_s(fp,"%le",&Max_quantum_width);
    if(Max_quantum_width>1e-5) {
	printf("More than 100nm is a pretty long quantum well.\n It is likely that the schrodinger solver will fail.\n");
	printf("You may reduce this length setting the variable in the simulation.inp file\n");
	rest();
    }
    fscanf_s(fp,"%le",&Secure_length);
    if(Secure_length>1e-5) {
	printf("More than 100nm is a pretty long distance over calculating the tail of the wave function.\n Numerical problems may arise\n");
	printf("I suggest you to reduce this length setting the variable in the simulation.inp file\n");
	rest();
    }
    fscanf_s(fp,"%d",&Number_of_eigenvalues);
    skip_line(fp);
    skip_line(fp);
    fscanf_s(fp,"%d",&fluctuation);
    fscanf_s(fp,"%lf",&fluctuation_percentage);

    fclose(fp);

  }

/* ---------------------------------------- */
/* ---------------------------------------- */

void Condition::show() {

  printf("INPUT_FILE_NAME = %s\n",input_file_name);
  printf("iter=%d\t\terr=%d\t\tfile=%d\n",num_iteration,num_error,num_file);
  printf("schr=%d\t\tpois=%d\t\tcurr=%d\t\tcont=%d\n",num_schrodinger,num_poisson,num_current,num_continuity);
  printf("type=%d\t\t\tdebug=%d\t\tprec=%le\t fluctuation=%d\t fluctuation_percentage=%le\n",type,debug,precision,fluctuation,fluctuation_percentage);
  printf("ibias=%5.2lf\t\tfbias=%5.2lf\t\tdbias=%5.2lf\n",initial_bias,final_bias,step_bias);
  printf("Pz=%5.2lf\t\tPsp=%5.2lf\t\tleft = %lf\t\tright= %lf\n",Pz_percentage,Psp_percentage,barrier_left_contact,barrier_right_contact);
  printf("Max_quantum_width=%le\t\tSecure_length=%le\t\trelax_length=%le\n",Max_quantum_width,Secure_length,relax_length);
}





